﻿#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER

using System;
using System.Text.Json.Serialization;

namespace zijian666.Json;
/// <summary>
/// JSON 转换器
/// </summary>
public static class JsonConverters
{
    public static IEnumerable<JsonConverter> All()
    {

        yield return DateTime;
        yield return TimeSpan;
        yield return DateTimeOffset;
#if NET5_0_OR_GREATER
        yield return TimeOnly;
        yield return DateOnly;
#endif
        yield return Guid;
        yield return ProxyObject;
        yield return JsonElement;
    }
    /// <summary>
    /// 适用于 <seealso cref="System.DateTime"/> 类型的JSON转换器
    /// </summary>
    public static JsonConverter DateTime { get; } = new JsonValueConverter<DateTime>();
    /// <summary>
    /// 适用于 <seealso cref="System.TimeSpan"/> 类型的JSON转换器
    /// </summary>
    public static JsonConverter TimeSpan { get; } = new JsonValueConverter<TimeSpan>();
    /// <summary>
    /// 适用于 <seealso cref="System.DateTimeOffset"/> 类型的JSON转换器
    /// </summary>
    public static JsonConverter DateTimeOffset { get; } = new JsonValueConverter<DateTimeOffset>();
#if NET5_0_OR_GREATER
    /// <summary>
    /// 适用于 <seealso cref="System.TimeOnly"/> 类型的JSON转换器
    /// </summary>
    public static JsonConverter TimeOnly { get; } = new JsonValueConverter<TimeOnly>();

    /// <summary>
    /// 适用于 <seealso cref="System.DateOnly"/> 类型的JSON转换器
    /// </summary>
    public static JsonConverter DateOnly { get; } = new JsonValueConverter<DateOnly>();

#endif

    /// <summary>
    /// 适用于 <seealso cref="System.Guid"/> 类型的JSON转换器
    /// </summary>
    public static JsonConverter Guid { get; } = new JsonValueConverter<Guid>();
    /// <summary>
    /// 适用于代理对象类型的JSON转换器, 例如动态类型, <seealso cref="System.IConvertible"/> "/>等
    /// </summary>
    public static JsonConverter ProxyObject { get; } = new ProxyObjectJsonConvererFactory();
    /// <summary>
    /// 适用于 <seealso cref="System.Text.Json.JsonElement"/> 类型的JSON转换器
    /// </summary>
    public static JsonConverter JsonElement { get; } = new JsonElementTranslator();
}


#endif